package logic

import (
	"context"
	"user/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLogic) Add(req *types.AddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	Add, err := l.svcCtx.UserRpc.Add(l.ctx, &userclient.AddRequest{
		Address: req.Address,
		Area:    req.Area,
		Rent:    int64(req.Rent),
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  "",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: "200",
		Msg:  "添加成功",
		Data: Add,
	}, nil
}
